/**
 * 1.创建文件夹
 * 2.复制 package.json
 *        foreEndApi
 *        third-park
 *        winSetting.json
 *        node.mysql.json
 * 3.初始化 yarn
 * */

const {
    buildPath,
    curPath,
} = require('./../buildSetting');
const fs = require('fs');
const path = require('path');
const copyDir = require('./../src/browser/fetchEvenDear/events/dir/copyDir');
const spawn = require('child_process').spawn;
// const dirClass = require('./../src/browser/fetchEvenDear/events/dir/index');
//
// const dirClassInstance = new dirClass();

const packageJson = {
    filename: path.join(buildPath, 'package.json'),
    content: {
        main: 'main.js',
        dependencies: {
            global: '^4.4.0',
            request: '^2.88.0',
            async: '^3.1.0',
            // electron: '2.0.5',
            exceljs: '^1.13.0',
            glob: '^7.1.4',
            log4js: '~2.5.2',
            mysql: '^2.17.1',
            nconf: '^0.8.4',
            ntlm: '^0.1.3',
            yargs: '^12.0.5',
        },
    },
};

// 1.
if (!fs.existsSync(buildPath)) {
    fs.mkdirSync(buildPath);
}

// 2.
fs.writeFileSync(packageJson.filename, JSON.stringify(packageJson.content, '', '\t'), 'utf-8');
copyDir.sync(path.join(curPath, 'foreEndApi'), path.join(buildPath, 'foreEndApi'));
copyDir.sync(path.join(curPath, 'third-park'), path.join(buildPath, 'third-park'));
fs.copyFileSync(path.join(curPath, 'winSetting.json'), path.join(buildPath, 'winSetting.json'));
fs.copyFileSync(path.join(curPath, 'node.mysql.json'), path.join(buildPath, 'node.mysql.json'));
spawn(`start cmd /k "cd ${buildPath} & yarn"`, {
    shell: true,
});
